using System.Collections.Generic;
using UnityEngine;

public class UIManager
{
    public static UIManager Instance = new UIManager();

    public enum UIEnum
    {
        None,
        DiePanel,
        HotKeyTipsPanel,
        WarningRoundPanel,
        AndroidOperationUI,
    }
    UIManager()
    {
        m_UIPrefabMap.Add(UIEnum.DiePanel, "Prefabs/UI/DiePanel");
        m_UIPrefabMap.Add(UIEnum.HotKeyTipsPanel, "Prefabs/UI/HotkeyTipsPanel");
        m_UIPrefabMap.Add(UIEnum.WarningRoundPanel, "Prefabs/UI/WarningRoundPanel");
        m_UIPrefabMap.Add(UIEnum.AndroidOperationUI, "Prefabs/UI/AndroidOperationUI");
    }
    Dictionary<UIEnum, string> m_UIPrefabMap = new Dictionary<UIEnum, string>();
    Dictionary<UIEnum, BaseUI> m_UIInstanceMap = new Dictionary<UIEnum, BaseUI>();
    public void Init()
    {
    }
    Canvas m_MainCanvas = null;
    public BaseUI OpenUI(UIEnum uiEnum)
    {
        if (!m_MainCanvas)
        {
            m_MainCanvas = GameObject.FindGameObjectWithTag("MainCanvas").GetComponent<Canvas>();
        }

        if (!m_UIPrefabMap.ContainsKey(uiEnum))
            return null;
        if (!m_UIInstanceMap.ContainsKey(uiEnum))
        {
            var uiObj = Resources.Load<BaseUI>(m_UIPrefabMap[uiEnum]);
            if (uiObj)
            {
                m_UIInstanceMap.Add(uiEnum, GameObject.Instantiate(uiObj, m_MainCanvas.transform));
            }
            else
            {
                Debug.LogError("û�ҵ�ui��prefab�������" + m_UIPrefabMap[uiEnum] + "��");
                return null;
            }
        }
        if (m_UIInstanceMap.ContainsKey(uiEnum))
        {
            m_UIInstanceMap[uiEnum].gameObject.SetActive(true);
        }
        return m_UIInstanceMap[uiEnum];
    }

    public void CloseUI(UIEnum uiEnum)
    {
        if (m_UIInstanceMap.ContainsKey(uiEnum))
        {
            m_UIInstanceMap[uiEnum].gameObject.SetActive(false);
        }
    }
    public void Update()
    {

    }
}
